<!--{include admin_header}-->
                <div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
<!--{include admin_breadcrumb}-->
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>{$_G['admincp']['actname']}<small><i class="icon-double-angle-right"></i>{$_G['admincp']['optname']}</small></h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="row">
									<div class="col-xs-12">
										<div class="tabbable">
											<div class="tab-content no-border no-padding">

                                                        <div id="id-message-new-navbar" class="message-navbar align-center clearfix">
															<div class="message-bar">
																<div class="message-toolbar">
																	<a href="javascript:void(0);" class="import-email btn btn-xs btn-message">
																		<i class="icon-save bigger-125"></i>
																		<span class="bigger-110">导入邮件</span>
																	</a>
																	<a href="javascript:void(0);" class="btn btn-xs btn-message">
																		<i class="icon-remove bigger-125"></i>
																		<span class="bigger-110">重写</span>
																	</a>
																</div>
															</div>

															<div class="message-item-bar">
																<div class="messagebar-item-left">
																	<a href="javascript:void(0);" onclick="history.go(-1);" class="btn-back-message-list no-hover-underline">
																		<i class="icon-arrow-left blue bigger-110 middle"></i>
																		<b class="middle bigger-110">返回</b>
																	</a>
																</div>

																<div class="messagebar-item-right">
																	<span class="inline btn-send-message">
																		<button type="button" class="btn btn-send-email btn-sm btn-primary no-border">
																			<span class="bigger-110">发送</span>

																			<i class="icon-arrow-right icon-on-right"></i>
																		</button>
																	</span>
																</div>
															</div>
														</div>


												<form id="id-message-form" class=" form-horizontal message-form  col-xs-12">
									<div class="">
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-recipient">接收人:</label>

											<div class="col-sm-9">
												<span class="input-icon">
													<input type="email" name="to" id="form-field-tags" value="" placeholder="接收人" />
												</span>
											</div>
										</div>

										<div class="hr hr-18 dotted"></div>

										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-subject">主题:</label>

											<div class="col-sm-6 col-xs-12">
												<div class="input-icon block col-xs-12 no-padding">
													<input maxlength="100" type="text" class="col-xs-12" name="subject" id="form-field-subject" placeholder="主题" />
													<i class="icon-comment-alt"></i>
												</div>
											</div>
										</div>

										<div class="hr hr-18 dotted"></div>

										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-subject">标签:</label>

											<div class="col-sm-6 col-xs-12">
												<div class=" block col-xs-6 no-padding">
													<input maxlength="100" type="text" class="col-xs-12" name="label" id="form-field-subject" placeholder="标签" />
												</div>
											</div>
										</div>

										<div class="hr hr-18 dotted"></div>

										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right">
												<span class="inline space-24 hidden-480"></span>
												内容:
											</label>

											<div class="col-sm-9">
												<div class="wysiwyg-editor"></div>
											</div>
										</div>

										<div class="hr hr-18 dotted"></div>

										<div class="form-group no-margin-bottom">
											<label class="col-sm-3 control-label no-padding-right">附件:</label>

											<div class="col-sm-9">
												<div id="form-attachments">
													<input type="file" name="attachment[]" />
												</div>
											</div>


										</div>

										<div class="align-right">
											<button id="id-add-attachment" type="button" class="btn btn-sm btn-danger">
												<i class="icon-paper-clip bigger-140"></i>添加附件
											</button>
										</div>

										<div class="space"></div>
									</div>
								</form><!-- /.tab-pane -->
											</div><!-- /.tab-content -->
										</div><!-- /.tabbable -->
									</div><!-- /.col -->
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
<!--{include admin_footer}-->
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="/static/ace/assets/css/jquery-ui-1.10.3.custom.min.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/select2.css" />

		<link rel="stylesheet" href="/static/ace/assets/css/ace.min.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/ace-skins.min.css" />

		<!-- page specific plugin scripts -->

		<script type="text/template" id="customer-template">
                                                                                <tr>
                                                                                    <td class="">{name}</td>
                                                                                    <td class="hidden-480">{admin}</td>
                                                                                </tr>
        </script>

		<script src="/static/ace/assets/js/markdown/markdown.min.js"></script>
		<script src="/static/ace/assets/js/markdown/bootstrap-markdown.min.js"></script>

		<script src="/static/ace/assets/js/fuelux/fuelux.wizard.min.js"></script>
		<script src="/static/ace/assets/js/jquery.validate.min.js"></script>
		<script src="/static/ace/assets/js/additional-methods.min.js"></script>
		<script src="/static/ace/assets/js/jquery.maskedinput.min.js"></script>
		<script src="/static/ace/assets/js/select2.min.js"></script>

		<script src="/static/ace/assets/js/jquery.hotkeys.min.js"></script>
		<script src="/static/ace/assets/js/bootstrap-wysiwyg.min.js"></script>
		<script src="/static/ace/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="/static/ace/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="/static/ace/assets/js/jquery.slimscroll.min.js"></script>


<!--		<script src="/static/ace/assets/js/bootstrap-tag.min.js"></script>-->
		<script src="/static/ace/assets/js/derek-tag.min.js"></script>
		<script type="text/javascript">
			D.Email = {
				init : function(){
					$('.import-email').on('click', function(){
						bootbox.dialog({
							title : '导入邮件',
							message : '<textarea id="import-emails" style="width:100%;" rows="8"></textarea>',
							buttons : {
								success : {
									label : '导入',
									className : 'btn-success',
									callback : function(){
										var emails = $('#import-emails').val();
										emails = D.str_replace("\n", ';', emails);
										var tag_input = $('#form-field-tags').clone();
										$('#form-field-tags').parent().parent().html(tag_input);
										var em_input = $('#form-field-tags');
										em_input.css('display', 'block');
										em_input.val(emails);
										if(! ( /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase())) ) {
											em_input.tag({
												placeholder:em_input.attr('placeholder'),
												source: null
											});
										}else {
											//display a textarea for old IE, because it doesn't support this plugin or another one I tried!
											em_input.after('<textarea id="'+em_input.attr('id')+'" name="'+em_input.attr('name')+'" rows="3">'+em_input.val()+'</textarea>').remove();
											//$('#form-field-tags').autosize({append: "\n"});
										}
									}
								},
								main: {
									label: "取消",
									className: "btn-primary"
								}
							}
						});
					});
					$('.btn-send-email').on('click', function(){
						var to = $('input[name="to"]').val();
						var subject = $('input[name="subject"]').val();
						var label = $('input[name="label"]').val();
						var content = $('.wysiwyg-editor').html();

						to = D.str_replace(';', ',', to);
						var tos = D.explode(',', to);
						var ready = tos.length;
						var post = sent = 0;
						if( !to || !ready ){
							bootbox.alert('收件人填写错误');
							return false;
						}
						if( !subject ){
							bootbox.alert('请填写主题');
							return false;
						}
						if( !content ){
							bootbox.alert('请填写内容');
							return false;
						}
						bootbox.dialog({
							title : '邮件发送中',
							message : '正在发送...第<span id="rsent">0</span>封邮件，共<span>'+ready+'封</span><br /><div class="progress progress-striped active"><div class="progress-bar-sent progress-bar progress-bar-yellow"></div></div>'
						});
						tos.forEach(function(k, v){
							var data = {
								to : k,
								subject : subject,
								content : content,
								label : label
							}
							var i = 0;
							$('#rsent').html(post + 1);
							D.ajax.postdata('?action=customer&operation=email_market', data, function(json){
								post++;
								if( !json.error ){
									sent += parseInt(json.data);
								}
								$('#rsent').html(post);
								var p = parseFloat((post/ready) * 100);
								
								$(".progress-bar-sent").css('width', p + '%');
								if( post == ready ){
									bootbox.hideAll();
									bootbox.alert('发送成功！共发送' + sent + '封邮件。');
								}
							});
						});
					});
				}
			}
			D.PageForm = {
				init : function(){
					/*
					{
						toolbar:
						[
							'bold',
							'italic',
							'strikethrough',
							'underline',
							null,
							'justifyleft',
							'justifycenter',
							'justifyright',
							null,
							'createLink',
							'unlink',
							null,
							'undo',
							'redo'
						]
					}
					*/
					$('.wysiwyg-editor').ace_wysiwyg().prev().addClass('wysiwyg-style1');
					//file input
					$('#form-attachments input[type=file]').ace_file_input()
					//and the wrap it inside .span7 for better display, perhaps
					.closest('.ace-file-input').addClass('width-90 inline').wrap('<div class="row file-input-container"><div class="col-sm-7"></div></div>');
			
					//the button to add a new file input
					$('#id-add-attachment').on('click', function(){
						var file = $('<input type="file" name="attachment[]" />').appendTo('#form-attachments');
						file.ace_file_input();
						file.closest('.ace-file-input').addClass('width-90 inline').wrap('<div class="row file-input-container"><div class="col-sm-7"></div></div>')
						.parent(/*.span7*/).append('<div class="action-buttons pull-right col-xs-1">\
							<a href="#" data-action="delete" class="middle">\
								<i class="icon-trash red bigger-130 middle"></i>\
							</a>\
						</div>').find('a[data-action=delete]').on('click', function(e){
							//the button that removes the newly inserted file input
							e.preventDefault();			
							$(this).closest('.row').hide(300, function(){
								$(this).remove();
							});
						});
					});
				}
			}
			D.Main = {
				init : function(){
					$('#province').change(function(){
						var pid = $(this).val();
						var html = '<option value="0">选择城市</option>';
						if( pid ){
							$('#city').html(html + '<option disabled>数据加载中</option>').select2({allowClear:true});
							D.ajax.get('?action=customer&operation=edit&act=public_get_city&dataid=' + pid, function(json){
								if ( json.data ){
									$.each(json.data, function(i, n){
										if ( n.id && n.name ){
											html += '<option value="'+n.id+'">'+n.name+'</option>';
										}
									});
								}
								$('#city').html(html).select2({allowClear:true});
							});
						}else{
							$('#city').html(html).select2({allowClear:true});
						}
					});
<!--{if !$customer}-->
					$('#name').on('blur', function(){
						var box = $(this);
						var last = $(this).attr('last');
						var name = box.val();
						box.attr('last', name);
						if( name && last != name ){
							$('.check-loading').removeClass('hide');
							box.attr('readonly', true);
	
							D.ajax.get('?action=customer&operation=edit&act=search&name=' + name, function(json){
								var html = '';
								if( !json.error || json.type == 'data' ){
									if( json.data && json.data.customers ){
										$.each(json.data.customers, function(i, n){
											var user = json.data.admins[n.adminid];
											if( user ){
												var company = json.data.companys[user.companyid];
												if( company ){
													var data = {
														name : n.name,
														admin : '[' + company.name + '] ' + (user.realname ? user.realname : user.username)
													};
													html += D.T.selector('#customer-template', data);
												}
											}
										});
									}
								}
								if( !html ){
									$('.customers-list').addClass('hide');
								}else{
									$('.customers-list').removeClass('hide').hide().slideDown();
									$('.customers-list .table tbody').html(html);
								}
								box.removeAttr('readonly');
								$('.check-loading').addClass('hide');
							});
						}
						if( !name ){
							$('.customers-list').addClass('hide');
						}
					});
<!--{/if}-->
				}
			}
			jQuery(function($) {
				$('[data-rel=tooltip]').tooltip();

				$(".select2").css('width','200px').select2({allowClear:true}).on('change', function(){
					$(this).closest('form').validate().element($(this));
				}); 
				$('.select-100').css('width', 100);
				var tag_input = $('#form-field-tags');
				if(! ( /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase())) ) {
					tag_input.tag({
						placeholder:tag_input.attr('placeholder'),
						source: null
					});
				}else {
					//display a textarea for old IE, because it doesn't support this plugin or another one I tried!
					tag_input.after('<textarea id="'+tag_input.attr('id')+'" name="'+tag_input.attr('name')+'" rows="3">'+tag_input.val()+'</textarea>').remove();
					//$('#form-field-tags').autosize({append: "\n"});
				}
			});
		</script>
<style>
.tags{ width:100%;}
</style>
</body>
</html>
